/*
 * Copyright (c) 2011, Michael van der Westhuizen
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *    - Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *    - Redistributions in binary form must reproduce the above
 *      copyright notice, this list of conditions and the following
 *      disclaimer in the documentation and/or other materials provided
 *      with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef PYXMLSEC1_KEYSDATA_C_MCVDW_20110126
#define PYXMLSEC1_KEYSDATA_C_MCVDW_20110126

#include "pyxmlsec.h"

#include <xmlsec/keysdata.h>



static PyObject * xmlsec1_xmlSecKeyDataIdsGet(PyObject * self, PyObject * arg)
{
    xmlSecPtrListPtr ptr;
    PyObject * ret;

    if (NULL == (ptr = xmlSecKeyDataIdsGet()))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataIdsGet);
        return NULL;
    }

    /* XXX: memory management? */
    if (NULL == (ret = xmlsec1mod_wrap_xmlSecPtrListPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecPtrListPtr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataIdsInit(PyObject * self, PyObject * arg)
{
    if (0 != xmlSecKeyDataIdsInit())
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataIdsInit);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataIdsShutdown(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataIdsShutdown();
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataIdsRegisterDefault(PyObject * self, PyObject * arg)
{
    if (0 != xmlSecKeyDataIdsRegisterDefault())
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataIdsRegisterDefault);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataIdsRegister(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataId id;

    if (NULL == (id = xmlsec1mod_unwrap_xmlSecKeyDataId(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (0 != xmlSecKeyDataIdsRegister(id))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataIdsRegister);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataCreate(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataId id;
    xmlSecKeyDataPtr ptr;
    PyObject * ret;

    if (NULL == (id = xmlsec1mod_unwrap_xmlSecKeyDataId(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyDataCreate(id)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataCreate);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyDataPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyDataPtr);
        xmlSecKeyDataDestroy(ptr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataDuplicate(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataPtr data;
    xmlSecKeyDataPtr ptr;
    PyObject * ret;

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyDataDuplicate(data)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataDuplicate);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyDataPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyDataPtr);
        xmlSecKeyDataDestroy(ptr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataDestroy(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataPtr data;

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    xmlSecKeyDataDestroy(data);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataGenerate(PyObject * self, PyObject * args, PyObject * kwds)
{
    xmlSecKeyDataPtr data;
    xmlSecSize sizeBits;
    xmlSecKeyDataType type;

    PyObject * arg1;
    int arg2;
    unsigned int arg3;

    static char * kwlist[] = {"data", "sizeBits", "kdtype", NULL};

    data = NULL;
    sizeBits = 0;
    type = 0;
    arg1 = NULL;
    arg2 = 0;
    arg3 = 0;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OiI", kwlist, &arg1, &arg2, &arg3))
    {
        return NULL;
    }

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    sizeBits = (xmlSecSize)arg2;
    type = (xmlSecKeyDataType)arg3;

    if (0 != xmlSecKeyDataGenerate(data, sizeBits, type))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataGenerate);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataGetType(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataPtr data;

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    return PyInt_FromLong((long)xmlSecKeyDataGetType(data));
}



static PyObject * xmlsec1_xmlSecKeyDataGetSize(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataPtr data;

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    return PyInt_FromLong((long)xmlSecKeyDataGetSize(data));
}



static PyObject * xmlsec1_xmlSecKeyDataGetIdentifier(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataPtr data;
    const xmlChar * id;

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (NULL == (id = xmlSecKeyDataGetIdentifier(data)))
    {
        Py_RETURN_NONE;
    }

    return PyBytes_FromString((const char *)id);
}



static PyObject * xmlsec1_xmlSecKeyDataDebugDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyDataPtr data;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"data", "output", NULL};

    arg1 = arg2 = NULL;
    data = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyDataDebugDump(data, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataDebugXmlDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyDataPtr data;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"data", "output", NULL};

    arg1 = arg2 = NULL;
    data = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyDataDebugXmlDump(data, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataXmlRead(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    PyObject * arg3;
    PyObject * arg4;
    xmlSecKeyDataId id;
    xmlSecKeyPtr key;
    xmlNodePtr node;
    xmlSecKeyInfoCtxPtr keyInfoCtx;

    static char * kwlist[] = {"id", "key", "node", "keyInfoCtx", NULL};

    arg1 = arg2 = arg3 = arg4 = NULL;
    id = NULL;
    key = NULL;
    node = NULL;
    keyInfoCtx = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOO", kwlist, &arg1, &arg2, &arg3, &arg4))
    {
        return NULL;
    }

    if (NULL == (id = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (node = xmlsec1mod_unwrap_xmlNodePtr(arg3)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlNodePtr);
        return NULL;
    }

    if (NULL == (keyInfoCtx = xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr(arg4)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr);
        return NULL;
    }

    if (0 != xmlSecKeyDataXmlRead(id, key, node, keyInfoCtx))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataXmlRead);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataXmlWrite(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    PyObject * arg3;
    PyObject * arg4;
    xmlSecKeyDataId id;
    xmlSecKeyPtr key;
    xmlNodePtr node;
    xmlSecKeyInfoCtxPtr keyInfoCtx;

    static char * kwlist[] = {"id", "key", "node", "keyInfoCtx", NULL};

    arg1 = arg2 = arg3 = arg4 = NULL;
    id = NULL;
    key = NULL;
    node = NULL;
    keyInfoCtx = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOO", kwlist, &arg1, &arg2, &arg3, &arg4))
    {
        return NULL;
    }

    if (NULL == (id = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (node = xmlsec1mod_unwrap_xmlNodePtr(arg3)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlNodePtr);
        return NULL;
    }

    if (NULL == (keyInfoCtx = xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr(arg4)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr);
        return NULL;
    }

    if (0 != xmlSecKeyDataXmlWrite(id, key, node, keyInfoCtx))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataXmlWrite);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataBinRead(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    PyObject * arg3;
    PyObject * arg4;
    xmlSecKeyDataId id;
    xmlSecKeyPtr key;
    xmlSecByte * buf;
    xmlSecSize bufSize;
    xmlSecKeyInfoCtxPtr keyInfoCtx;

    static char * kwlist[] = {"id", "key", "buf", "keyInfoCtx", NULL};

    arg1 = arg2 = arg3 = arg4 = NULL;
    id = NULL;
    key = NULL;
    buf = NULL;
    bufSize = 0;
    keyInfoCtx = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOO", kwlist, &arg1, &arg2, &arg3, &arg4))
    {
        return NULL;
    }

    if (NULL == (id = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (keyInfoCtx = xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr(arg4)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr);
        return NULL;
    }

    if (0 != xmlsec1_ByteArrayOrBytesToXmlSecBytes(arg3, &buf, &bufSize))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_ByteArrayOrBytesToXmlSecBytes);
        return NULL;
    }

    if (0 != xmlSecKeyDataBinRead(id, key, buf, bufSize, keyInfoCtx))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataBinRead);
        PyMem_Del(buf);
        return NULL;
    }

    PyMem_Del(buf);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataBinWrite(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    PyObject * arg3;
    xmlSecKeyDataId id;
    xmlSecKeyPtr key;
    xmlSecKeyInfoCtxPtr keyInfoCtx;
    xmlSecByte * buf;
    xmlSecSize bufSize;
    PyObject * ret;

    static char * kwlist[] = {"id", "key", "keyInfoCtx", NULL};

    arg1 = arg2 = arg3 = NULL;
    id = NULL;
    key = NULL;
    keyInfoCtx = NULL;
    buf = NULL;
    bufSize = 0;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOO", kwlist, &arg1, &arg2, &arg3))
    {
        return NULL;
    }

    if (NULL == (id = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (keyInfoCtx = xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr(arg3)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr);
        return NULL;
    }

    if (0 != xmlSecKeyDataBinWrite(id, key, &buf, &bufSize, keyInfoCtx))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataBinWrite);
        return NULL;
    }

    ret = PyByteArray_FromStringAndSize((const char *)buf, (Py_ssize_t)bufSize);
    xmlFree(buf);
    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataGetName(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataPtr data;
    const xmlChar * name;
    PyObject * ret;

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (NULL == (name = xmlSecKeyDataGetName(data)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataGetName);
        return NULL;
    }

    if (NULL == (ret = PyBytes_FromString((const char *)name)))
    {
        ENSURE_EXCEPTION_SET(PyBytes_FromString);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataIsValid(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataPtr data;

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (xmlSecKeyDataIsValid(data))
    {
        Py_RETURN_TRUE;
    }

    Py_RETURN_FALSE;
}



static PyObject * xmlsec1_xmlSecKeyDataCheckId(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyDataPtr data;
    xmlSecKeyDataId dataId;

    static char * kwlist[] = {"data", "dataId", NULL};

    arg1 = arg2 = NULL;
    data = NULL;
    dataId = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (NULL == (dataId = xmlsec1mod_unwrap_xmlSecKeyDataId(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (xmlSecKeyDataCheckId(data, dataId))
    {
        Py_RETURN_TRUE;
    }

    Py_RETURN_FALSE;
}



static PyObject * xmlsec1_xmlSecKeyDataCheckUsage(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    unsigned int arg2;
    xmlSecKeyDataPtr data;
    xmlSecKeyDataUsage usg;

    static char * kwlist[] = {"data", "usg", NULL};

    arg1 = NULL;
    arg2 = 0;
    data = NULL;
    usg = xmlSecKeyDataUsageUnknown;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OI", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    usg = (xmlSecKeyDataUsage)arg2;

    if (xmlSecKeyDataCheckUsage(data, usg))
    {
        Py_RETURN_TRUE;
    }

    Py_RETURN_FALSE;
}



static PyObject * xmlsec1_xmlSecKeyDataCheckSize(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    int arg2;
    xmlSecKeyDataPtr data;
    xmlSecSize size;

    static char * kwlist[] = {"data", "size", NULL};

    arg1 = NULL;
    arg2 = 0;
    data = NULL;
    size = 0;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oi", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    size = (xmlSecSize)arg2;

    if (xmlSecKeyDataCheckSize(data, size))
    {
        Py_RETURN_TRUE;
    }

    Py_RETURN_FALSE;
}



static PyObject * xmlsec1_xmlSecKeyDataKlassGetName(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataId klass;
    const xmlChar * name;
    PyObject * ret;

    if (NULL == (klass = xmlsec1mod_unwrap_xmlSecKeyDataId(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (name = xmlSecKeyDataKlassGetName(klass)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataKlassGetName);
        return NULL;
    }

    if (NULL == (ret = PyBytes_FromString((const char *)name)))
    {
        ENSURE_EXCEPTION_SET(PyBytes_FromString);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataListGetKlass(PyObject * self, PyObject * args)
{
    xmlSecPtrListId id;
    PyObject * ret;

    if (NULL == (id = xmlSecKeyDataListGetKlass()))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataListGetKlass);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecPtrListId(id)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecPtrListId);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataIdListGetKlass(PyObject * self, PyObject * args)
{
    xmlSecPtrListId id;
    PyObject * ret;

    if (NULL == (id = xmlSecKeyDataIdListGetKlass()))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataIdListGetKlass);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecPtrListId(id)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecPtrListId);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataIdListFind(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecPtrListPtr list;
    xmlSecKeyDataId dataId;

    static char * kwlist[] = {"tlist", "dataId", NULL};

    arg1 = arg2 = NULL;
    list = NULL;
    dataId = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (list = xmlsec1mod_unwrap_xmlSecPtrListPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecPtrListPtr);
        return NULL;
    }

    if (NULL == (dataId = xmlsec1mod_unwrap_xmlSecKeyDataId(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    switch (xmlSecKeyDataIdListFind(list, dataId))
    {
        case 0:
        {
            Py_RETURN_FALSE;
        }
        case 1:
        {
            Py_RETURN_TRUE;
        }
        default:
        {
            ENSURE_EXCEPTION_SET(xmlSecKeyDataIdListFind);
            break;
        }
    }

    return NULL;
}



static PyObject * xmlsec1_xmlSecKeyDataIdListFindByNode(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    PyObject * arg3;
    unsigned int arg4;
    xmlSecPtrListPtr list;
    xmlChar * nodeName;
    xmlChar * nodeNs;
    xmlSecKeyDataUsage usage;
    xmlSecKeyDataId ptr;
    PyObject * ret;

    static char * kwlist[] = {"tlist", "nodeName", "nodeNs", "usage", NULL};

    arg1 = arg2 = arg3 = NULL;
    arg4 = 0;
    list = NULL;
    nodeName = nodeNs = NULL;
    usage = xmlSecKeyDataUsageUnknown;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOI", kwlist, &arg1, &arg2, &arg3, &arg4))
    {
        return NULL;
    }

    if (NULL == (list = xmlsec1mod_unwrap_xmlSecPtrListPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecPtrListPtr);
        return NULL;
    }

    usage = (xmlSecKeyDataUsage)arg4;

    if (0 != xmlsec1_UnicodeOrBytesToXmlCharPtr(arg2, &nodeName, NULL))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_UnicodeOrBytesToXmlCharPtr);
        return NULL;
    }

    if (0 != xmlsec1_UnicodeOrBytesToXmlCharPtr(arg3, &nodeNs, NULL))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_UnicodeOrBytesToXmlCharPtr);
        xmlFree(nodeName);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyDataIdListFindByNode(list, nodeName, nodeNs, usage)))
    {
        xmlFree(nodeName);
        xmlFree(nodeNs);

        if (PyErr_Occurred())
        {
            ENSURE_EXCEPTION_SET(xmlSecKeyDataIdListFindByNode);
            return NULL;
        }

        Py_RETURN_NONE;
    }

    xmlFree(nodeName);
    xmlFree(nodeNs);

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyDataId(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyDataId);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataIdListFindByHref(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    unsigned int arg3;
    xmlSecPtrListPtr list;
    xmlChar * href;
    xmlSecKeyDataUsage usage;
    xmlSecKeyDataId ptr;
    PyObject * ret;

    static char * kwlist[] = {"tlist", "href", "usage", NULL};

    arg1 = arg2 = NULL;
    arg3 = 0;
    list = NULL;
    href = NULL;
    usage = xmlSecKeyDataUsageUnknown;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOI", kwlist, &arg1, &arg2, &arg3))
    {
        return NULL;
    }

    if (NULL == (list = xmlsec1mod_unwrap_xmlSecPtrListPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecPtrListPtr);
        return NULL;
    }

    usage = (xmlSecKeyDataUsage)arg3;

    if (0 != xmlsec1_UnicodeOrBytesToXmlCharPtr(arg2, &href, NULL))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_UnicodeOrBytesToXmlCharPtr);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyDataIdListFindByHref(list, href, usage)))
    {
        xmlFree(href);

        if (PyErr_Occurred())
        {
            ENSURE_EXCEPTION_SET(xmlSecKeyDataIdListFindByHref);
            return NULL;
        }

        Py_RETURN_NONE;
    }

    xmlFree(href);

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyDataId(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyDataId);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataIdListFindByName(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    unsigned int arg3;
    xmlSecPtrListPtr list;
    xmlChar * name;
    xmlSecKeyDataUsage usage;
    xmlSecKeyDataId ptr;
    PyObject * ret;

    static char * kwlist[] = {"tlist", "name", "usage", NULL};

    arg1 = arg2 = NULL;
    arg3 = 0;
    list = NULL;
    name = NULL;
    usage = xmlSecKeyDataUsageUnknown;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOI", kwlist, &arg1, &arg2, &arg3))
    {
        return NULL;
    }

    if (NULL == (list = xmlsec1mod_unwrap_xmlSecPtrListPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecPtrListPtr);
        return NULL;
    }

    usage = (xmlSecKeyDataUsage)arg3;

    if (0 != xmlsec1_UnicodeOrBytesToXmlCharPtr(arg2, &name, NULL))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_UnicodeOrBytesToXmlCharPtr);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyDataIdListFindByName(list, name, usage)))
    {
        xmlFree(name);

        if (PyErr_Occurred())
        {
            ENSURE_EXCEPTION_SET(xmlSecKeyDataIdListFindByName);
            return NULL;
        }

        Py_RETURN_NONE;
    }

    xmlFree(name);

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyDataId(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyDataId);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataIdListDebugDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecPtrListPtr list;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"list", "output", NULL};

    arg1 = arg2 = NULL;
    list = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (list = xmlsec1mod_unwrap_xmlSecPtrListPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecPtrListPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyDataIdListDebugDump(list, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataIdListDebugXmlDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecPtrListPtr list;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"list", "output", NULL};

    arg1 = arg2 = NULL;
    list = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (list = xmlsec1mod_unwrap_xmlSecPtrListPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecPtrListPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyDataIdListDebugXmlDump(list, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueInitialize(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataPtr data;

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (0 != xmlSecKeyDataBinaryValueInitialize(data))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataBinaryValueInitialize);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueDuplicate(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyDataPtr dst;
    xmlSecKeyDataPtr src;

    static char * kwlist[] = {"dst", "src", NULL};

    arg1 = arg2 = NULL;
    dst = src = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (dst = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (NULL == (src = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (0 != xmlSecKeyDataBinaryValueDuplicate(dst, src))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataBinaryValueDuplicate);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueFinalize(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataPtr data;

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    xmlSecKeyDataBinaryValueFinalize(data);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueXmlRead(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    PyObject * arg3;
    PyObject * arg4;
    xmlSecKeyDataId id;
    xmlSecKeyPtr key;
    xmlNodePtr node;
    xmlSecKeyInfoCtxPtr keyInfoCtx;

    static char * kwlist[] = {"id", "key", "node", "keyInfoCtx", NULL};

    arg1 = arg2 = arg3 = arg4 = NULL;
    id = NULL;
    key = NULL;
    node = NULL;
    keyInfoCtx = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOO", kwlist, &arg1, &arg2, &arg3, &arg4))
    {
        return NULL;
    }

    if (NULL == (id = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (node = xmlsec1mod_unwrap_xmlNodePtr(arg3)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlNodePtr);
        return NULL;
    }

    if (NULL == (keyInfoCtx = xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr(arg4)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr);
        return NULL;
    }

    if (0 != xmlSecKeyDataBinaryValueXmlRead(id, key, node, keyInfoCtx))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataBinaryValueXmlRead);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueXmlWrite(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    PyObject * arg3;
    PyObject * arg4;
    xmlSecKeyDataId id;
    xmlSecKeyPtr key;
    xmlNodePtr node;
    xmlSecKeyInfoCtxPtr keyInfoCtx;

    static char * kwlist[] = {"id", "key", "node", "keyInfoCtx", NULL};

    arg1 = arg2 = arg3 = arg4 = NULL;
    id = NULL;
    key = NULL;
    node = NULL;
    keyInfoCtx = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOO", kwlist, &arg1, &arg2, &arg3, &arg4))
    {
        return NULL;
    }

    if (NULL == (id = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (node = xmlsec1mod_unwrap_xmlNodePtr(arg3)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlNodePtr);
        return NULL;
    }

    if (NULL == (keyInfoCtx = xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr(arg4)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr);
        return NULL;
    }

    if (0 != xmlSecKeyDataBinaryValueXmlWrite(id, key, node, keyInfoCtx))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataBinaryValueXmlWrite);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueBinRead(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    PyObject * arg3;
    PyObject * arg4;
    xmlSecKeyDataId id;
    xmlSecKeyPtr key;
    xmlSecByte * buf;
    xmlSecSize bufSize;
    xmlSecKeyInfoCtxPtr keyInfoCtx;

    static char * kwlist[] = {"id", "key", "buf", "keyInfoCtx", NULL};

    arg1 = arg2 = arg3 = arg4 = NULL;
    id = NULL;
    key = NULL;
    buf = NULL;
    bufSize = 0;
    keyInfoCtx = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOO", kwlist, &arg1, &arg2, &arg3, &arg4))
    {
        return NULL;
    }

    if (NULL == (id = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (keyInfoCtx = xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr(arg4)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr);
        return NULL;
    }

    if (0 != xmlsec1_ByteArrayOrBytesToXmlSecBytes(arg3, &buf, &bufSize))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_ByteArrayOrBytesToXmlSecBytes);
        return NULL;
    }

    if (0 != xmlSecKeyDataBinaryValueBinRead(id, key, buf, bufSize, keyInfoCtx))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataBinaryValueBinRead);
        PyMem_Del(buf);
        return NULL;
    }

    PyMem_Del(buf);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueBinWrite(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    PyObject * arg3;
    xmlSecKeyDataId id;
    xmlSecKeyPtr key;
    xmlSecKeyInfoCtxPtr keyInfoCtx;
    xmlSecByte * buf;
    xmlSecSize bufSize;
    PyObject * ret;

    static char * kwlist[] = {"id", "key", "keyInfoCtx", NULL};

    arg1 = arg2 = arg3 = NULL;
    id = NULL;
    key = NULL;
    keyInfoCtx = NULL;
    buf = NULL;
    bufSize = 0;
    ret = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOO", kwlist, &arg1, &arg2, &arg3))
    {
        return NULL;
    }

    if (NULL == (id = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (keyInfoCtx = xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr(arg3)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr);
        return NULL;
    }

    if (0 != xmlSecKeyDataBinaryValueBinWrite(id, key, &buf, &bufSize, keyInfoCtx))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataBinaryValueBinWrite);
        return NULL;
    }

    ret = PyByteArray_FromStringAndSize((const char *)buf, (Py_ssize_t)bufSize);
    xmlFree(buf);
    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueDebugDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyDataPtr data;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"data", "output", NULL};

    arg1 = arg2 = NULL;
    data = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyDataBinaryValueDebugDump(data, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueDebugXmlDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyDataPtr data;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"data", "output", NULL};

    arg1 = arg2 = NULL;
    data = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyDataBinaryValueDebugXmlDump(data, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueGetSize(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataPtr data;
    xmlSecSize size;

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    size = xmlSecKeyDataBinaryValueGetSize(data);

    if (PyErr_Occurred())
    {
        return NULL;
    }

    return PyInt_FromLong((long)size);
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueGetBuffer(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataPtr data;
    xmlSecBufferPtr buffer;
    PyObject * ret;

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (NULL == (buffer = xmlSecKeyDataBinaryValueGetBuffer(data)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataBinaryValueGetBuffer);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecBufferPtr(buffer)))
    {
        /* memory management? */
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecBufferPtr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataBinaryValueSetBuffer(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyDataPtr data;
    xmlSecByte * buf;
    xmlSecSize bufSize;

    static char * kwlist[] = {"data", "buf", NULL};

    arg1 = arg2 = NULL;
    data = NULL;
    buf = NULL;
    bufSize = 0;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (0 != xmlsec1_ByteArrayOrBytesToXmlSecBytes(arg2, &buf, &bufSize))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_ByteArrayOrBytesToXmlSecBytes);
        return NULL;
    }

    if (0 != xmlSecKeyDataBinaryValueSetBuffer(data, buf, bufSize))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataBinaryValueSetBuffer);
        PyMem_Del(buf);
        return NULL;
    }

    PyMem_Del(buf);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataStoreCreate(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataStoreId id;
    xmlSecKeyDataStorePtr ptr;
    PyObject * ret;

    if (NULL == (id = xmlsec1mod_unwrap_xmlSecKeyDataStoreId(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataStoreId);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyDataStoreCreate(id)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataStoreCreate);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyDataStorePtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyDataStorePtr);
        xmlSecKeyDataStoreDestroy(ptr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataStoreDestroy(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataStorePtr store;

    if (NULL == (store = xmlsec1mod_unwrap_xmlSecKeyDataStorePtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataStorePtr);
        return NULL;
    }

    xmlSecKeyDataStoreDestroy(store);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDataStoreGetName(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataStorePtr store;
    const xmlChar * name;
    PyObject * ret;

    if (NULL == (store = xmlsec1mod_unwrap_xmlSecKeyDataStorePtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataStorePtr);
        return NULL;
    }

    if (NULL == (name = xmlSecKeyDataStoreGetName(store)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataStoreGetName);
        return NULL;
    }

    if (NULL == (ret = PyBytes_FromString((const char *)name)))
    {
        ENSURE_EXCEPTION_SET(PyBytes_FromString);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataStoreIsValid(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataStorePtr store;

    if (NULL == (store = xmlsec1mod_unwrap_xmlSecKeyDataStorePtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataStorePtr);
        return NULL;
    }

    if (xmlSecKeyDataStoreIsValid(store))
    {
        Py_RETURN_TRUE;
    }

    Py_RETURN_FALSE;
}



static PyObject * xmlsec1_xmlSecKeyDataStoreCheckId(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyDataStorePtr store;
    xmlSecKeyDataStoreId storeId;

    static char * kwlist[] = {"store", "storeId", NULL};

    arg1 = arg2 = NULL;
    store = NULL;
    storeId = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (store = xmlsec1mod_unwrap_xmlSecKeyDataStorePtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataStorePtr);
        return NULL;
    }

    if (NULL == (storeId = xmlsec1mod_unwrap_xmlSecKeyDataStoreId(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataStoreId);
        return NULL;
    }

    if (xmlSecKeyDataStoreCheckId(store, storeId))
    {
        Py_RETURN_TRUE;
    }

    Py_RETURN_FALSE;
}



static PyObject * xmlsec1_xmlSecKeyDataStoreCheckSize(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    unsigned int arg2;
    xmlSecKeyDataStorePtr store;
    xmlSecSize size;

    static char * kwlist[] = {"store", "size", NULL};

    arg1 = NULL;
    arg2 = 0;
    store = NULL;
    size = 0;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OI", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (store = xmlsec1mod_unwrap_xmlSecKeyDataStorePtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataStorePtr);
        return NULL;
    }

    size = (xmlSecSize)arg2;

    if (xmlSecKeyDataStoreCheckSize(store, size))
    {
        Py_RETURN_TRUE;
    }

    Py_RETURN_FALSE;
}



static PyObject * xmlsec1_xmlSecKeyDataStoreKlassGetName(PyObject * self, PyObject * arg)
{
    xmlSecKeyDataStoreId klass;
    const xmlChar * name;
    PyObject * ret;

    if (NULL == (klass = xmlsec1mod_unwrap_xmlSecKeyDataStoreId(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataStoreId);
        return NULL;
    }

    if (NULL == (name = xmlSecKeyDataStoreKlassGetName(klass)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataStoreKlassGetName);
        return NULL;
    }

    if (NULL == (ret = PyBytes_FromString((const char *)name)))
    {
        ENSURE_EXCEPTION_SET(PyBytes_FromString);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDataStorePtrListGetKlass(PyObject * self, PyObject * args)
{
    xmlSecPtrListId id;
    PyObject * ret;

    if (NULL == (id = xmlSecKeyDataStorePtrListGetKlass()))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDataStorePtrListGetKlass);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecPtrListId(id)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecPtrListId);
        return NULL;
    }

    return ret;
}


#if 0
-- typedef xmlSecKeyDataUsage;
-- #define xmlSecKeyDataUsageUnknown
-- #define xmlSecKeyDataUsageKeyInfoNodeRead
-- #define xmlSecKeyDataUsageKeyInfoNodeWrite
-- #define xmlSecKeyDataUsageKeyValueNodeRead
-- #define xmlSecKeyDataUsageKeyValueNodeWrite
-- #define xmlSecKeyDataUsageRetrievalMethodNodeXml
-- #define xmlSecKeyDataUsageRetrievalMethodNodeBin
-- #define xmlSecKeyDataUsageAny
-- #define xmlSecKeyDataUsageKeyInfoNode
-- #define xmlSecKeyDataUsageKeyValueNode
-- #define xmlSecKeyDataUsageRetrievalMethodNode
-- typedef xmlSecKeyDataType;
-- #define xmlSecKeyDataTypeUnknown
-- #define xmlSecKeyDataTypeNone
-- #define xmlSecKeyDataTypePublic
-- #define xmlSecKeyDataTypePrivate
-- #define xmlSecKeyDataTypeSymmetric
-- #define xmlSecKeyDataTypeSession
-- #define xmlSecKeyDataTypePermanent
-- #define xmlSecKeyDataTypeTrusted
-- #define xmlSecKeyDataTypeAny
-- enum xmlSecKeyDataFormat;
-- xmlSecPtrListPtr xmlSecKeyDataIdsGet(void);
-- int xmlSecKeyDataIdsInit(void);
-- void xmlSecKeyDataIdsShutdown(void);
-- int xmlSecKeyDataIdsRegisterDefault(void);
-- int xmlSecKeyDataIdsRegister(xmlSecKeyDataId id);

-- struct xmlSecKeyData;
-- xmlSecKeyDataPtr xmlSecKeyDataCreate(xmlSecKeyDataId id);
-- xmlSecKeyDataPtr xmlSecKeyDataDuplicate(xmlSecKeyDataPtr data);
-- void xmlSecKeyDataDestroy(xmlSecKeyDataPtr data);
-- int xmlSecKeyDataGenerate(xmlSecKeyDataPtr data, xmlSecSize sizeBits, xmlSecKeyDataType type);
-- xmlSecKeyDataType xmlSecKeyDataGetType(xmlSecKeyDataPtr data);
-- xmlSecSize xmlSecKeyDataGetSize(xmlSecKeyDataPtr data);
-- const xmlChar* xmlSecKeyDataGetIdentifier(xmlSecKeyDataPtr data);
-- void xmlSecKeyDataDebugDump(xmlSecKeyDataPtr data, FILE *output);
-- void xmlSecKeyDataDebugXmlDump(xmlSecKeyDataPtr data, FILE *output);
-- int xmlSecKeyDataXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- int xmlSecKeyDataXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- int xmlSecKeyDataBinRead(xmlSecKeyDataId id, xmlSecKeyPtr key, const xmlSecByte *buf, xmlSecSize bufSize, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- int xmlSecKeyDataBinWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlSecByte **buf, xmlSecSize *bufSize, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- #define xmlSecKeyDataGetName(data)
-- #define xmlSecKeyDataIsValid(data)
-- #define xmlSecKeyDataCheckId(data, dataId)
-- #define xmlSecKeyDataCheckUsage(data, usg)
-- #define xmlSecKeyDataCheckSize(data, size)
#define xmlSecKeyDataIdUnknown
-- int (*xmlSecKeyDataInitMethod)(xmlSecKeyDataPtr data);
-- int (*xmlSecKeyDataDuplicateMethod)(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src);
-- void (*xmlSecKeyDataFinalizeMethod)(xmlSecKeyDataPtr data);
-- int (*xmlSecKeyDataXmlReadMethod)(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- int (*xmlSecKeyDataXmlWriteMethod)(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- int (*xmlSecKeyDataBinReadMethod)(xmlSecKeyDataId id, xmlSecKeyPtr key, const xmlSecByte *buf, xmlSecSize bufSize, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- int (*xmlSecKeyDataBinWriteMethod)(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlSecByte **buf, xmlSecSize *bufSize, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- int (*xmlSecKeyDataGenerateMethod)(xmlSecKeyDataPtr data, xmlSecSize sizeBits, xmlSecKeyDataType type);
-- xmlSecKeyDataType (*xmlSecKeyDataGetTypeMethod)(xmlSecKeyDataPtr data);
-- xmlSecSize (*xmlSecKeyDataGetSizeMethod)(xmlSecKeyDataPtr data);
-- const xmlChar * (*xmlSecKeyDataGetIdentifierMethod)(xmlSecKeyDataPtr data);
-- void (*xmlSecKeyDataDebugDumpMethod)(xmlSecKeyDataPtr data, FILE *output);

-- struct xmlSecKeyDataKlass;
-- #define xmlSecKeyDataKlassGetName(klass)
-- #define xmlSecKeyDataListId
-- xmlSecPtrListId xmlSecKeyDataListGetKlass(void);

-- #define xmlSecKeyDataIdListId
-- xmlSecPtrListId xmlSecKeyDataIdListGetKlass(void);
-- int xmlSecKeyDataIdListFind(xmlSecPtrListPtr list, xmlSecKeyDataId dataId);
-- xmlSecKeyDataId xmlSecKeyDataIdListFindByNode(xmlSecPtrListPtr list, const xmlChar *nodeName, const xmlChar *nodeNs, xmlSecKeyDataUsage usage);
-- xmlSecKeyDataId xmlSecKeyDataIdListFindByHref(xmlSecPtrListPtr list, const xmlChar *href, xmlSecKeyDataUsage usage);
-- xmlSecKeyDataId xmlSecKeyDataIdListFindByName(xmlSecPtrListPtr list, const xmlChar *name, xmlSecKeyDataUsage usage);
-- void xmlSecKeyDataIdListDebugDump(xmlSecPtrListPtr list, FILE *output);
-- void xmlSecKeyDataIdListDebugXmlDump(xmlSecPtrListPtr list, FILE *output);

-- #define xmlSecKeyDataBinarySize
-- int xmlSecKeyDataBinaryValueInitialize(xmlSecKeyDataPtr data);
-- int xmlSecKeyDataBinaryValueDuplicate(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src);
-- void xmlSecKeyDataBinaryValueFinalize(xmlSecKeyDataPtr data);
-- int xmlSecKeyDataBinaryValueXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- int xmlSecKeyDataBinaryValueXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- int xmlSecKeyDataBinaryValueBinRead(xmlSecKeyDataId id, xmlSecKeyPtr key, const xmlSecByte *buf, xmlSecSize bufSize, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- int xmlSecKeyDataBinaryValueBinWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlSecByte **buf, xmlSecSize *bufSize, xmlSecKeyInfoCtxPtr keyInfoCtx);
-- void xmlSecKeyDataBinaryValueDebugDump(xmlSecKeyDataPtr data, FILE *output);
-- void xmlSecKeyDataBinaryValueDebugXmlDump(xmlSecKeyDataPtr data, FILE *output);
-- xmlSecSize xmlSecKeyDataBinaryValueGetSize(xmlSecKeyDataPtr data);
-- xmlSecBufferPtr xmlSecKeyDataBinaryValueGetBuffer(xmlSecKeyDataPtr data);
-- int xmlSecKeyDataBinaryValueSetBuffer(xmlSecKeyDataPtr data, const xmlSecByte *buf, xmlSecSize bufSize);

-- struct xmlSecKeyDataStore;
-- xmlSecKeyDataStorePtr xmlSecKeyDataStoreCreate(xmlSecKeyDataStoreId id);
-- void xmlSecKeyDataStoreDestroy(xmlSecKeyDataStorePtr store);
-- #define xmlSecKeyDataStoreGetName(store)
-- #define xmlSecKeyDataStoreIsValid(store)
-- #define xmlSecKeyDataStoreCheckId(store, storeId)
-- #define xmlSecKeyDataStoreCheckSize(store, size)
#define xmlSecKeyDataStoreIdUnknown
-- int (*xmlSecKeyDataStoreInitializeMethod) (xmlSecKeyDataStorePtr store);
-- void (*xmlSecKeyDataStoreFinalizeMethod) (xmlSecKeyDataStorePtr store);
-- struct xmlSecKeyDataStoreKlass;
-- #define xmlSecKeyDataStoreKlassGetName(klass)

-- #define xmlSecKeyDataStorePtrListId
-- xmlSecPtrListId xmlSecKeyDataStorePtrListGetKlass(void);
#endif

#endif
